              package com.java.diagnostics.visualizer.parser.vgc.constants;
              
              import com.java.diagnostics.visualizer.impl.factory.LogFactory;
              import java.text.DateFormat;
              import java.text.ParseException;
              import java.text.SimpleDateFormat;
              import java.util.Date;
              import java.util.Locale;
              import java.util.TimeZone;
              import java.util.logging.Logger;
              
              public abstract class DateConverter
              {
                private static final Logger TRACE = LogFactory.getTrace(DateConverter.class);
                private static final double UNPARSED = -1.0D;
                protected static final Locale defaultLogLocale = Locale.US;
              
                private DateFormat[] formats = null;
              
                private final DateFormat[] formatters = getDateFormats();
              
                private int preferredIndex = 0;
              
                protected abstract String[] getUnlocalisedDateStrings();
              
                protected TimeZone[] getTimezonesForDateStrings()
                {
                  return null;
                }
              
                protected DateFormat[] getDateFormats()
                {
                  if (this.formats == null) {
                    Locale[] locales = Locale.getAvailableLocales();
                    String[] strings = getUnlocalisedDateStrings();
                    TimeZone[] timezones = getTimezonesForDateStrings();
              
                    if (timezones == null) {
                      timezones = new TimeZone[strings.length];
                    }
                    this.formats = new DateFormat[(locales.length + 1) * strings.length];
              
                    int index = 0;
                    Locale locale = defaultLogLocale;
                    for (int j = 0; j < strings.length; j++) {
                      String string = strings[j];
                      SimpleDateFormat format = constructFormat(locale, string, 
                        timezones[j]);
                      this.formats[index] = format;
                      index++;
                    }
                    for (int i = 0; i < locales.length; i++) {
                      locale = locales[i];
                      for (int j = 0; j < strings.length; j++) {
                        String string = strings[j];
                        SimpleDateFormat format = constructFormat(locale, string, 
                          timezones[j]);
                        this.formats[index] = format;
                        index++;
                      }
                    }
                  }
              
                  return this.formats;
                }
              
                private SimpleDateFormat constructFormat(Locale locale, String string, TimeZone timeZone)
                {
                  SimpleDateFormat format = new SimpleDateFormat(string, locale);
              
                  if (timeZone != null) {
                    format.setTimeZone(timeZone);
                  }
                  return format;
                }
              
                protected double parse(String stringValue)
                {
                  double date = -1.0D;
                  int attempts = 0;
                  while ((date == -1.0D) && (attempts < this.formatters.length)) {
                    try {
                      attempts++;
                      date = this.formatters[this.preferredIndex].parse(stringValue).getTime();
                    }
                    catch (ParseException localParseException) {
                      TRACE.finer("Could not parse into a date: " + stringValue);
                      this.preferredIndex += 1;
                      this.preferredIndex %= this.formatters.length;
                    }
              
                  }
              
                  return date;
                }
              }

